import sys, pygame

#main init
pygame.init()
rozmiar_okna = width, height = 800, 600
okno = pygame.display.set_mode(rozmiar_okna)

#graphic init
pilka = pygame.image.load("pilka.gif")
pilkarect = pilka.get_rect()
okno.blit(pilka, pilkarect)
pygame.display.flip()

tapeta = pygame.image.load("tapeta.gif")
tapetarect = tapeta.get_rect()

paletka = pygame.image.load("paletka.gif")
paletkarect = paletka.get_rect()
paletkarect = paletkarect.move([350, 500])
predkosc_paletki = [0,0]

predkosc = [1,1]

#main loop
while 1: #pilkarect.bottom <= height:
    pilkarect = pilkarect.move(predkosc)
    okno.blit(tapeta, tapetarect)
    okno.blit(pilka, pilkarect)
    okno.blit(paletka, paletkarect)
    paletkarect = paletkarect.move(predkosc_paletki)
    
    
    #kolizje
    if pilkarect.left < 0 or pilkarect.right > width:
        predkosc[0] = -predkosc[0]
    if pilkarect.top < 0 or pilkarect.bottom > height:
        predkosc[1] = -predkosc[1]

    if paletkarect.left < 0 or paletkarect.right > width:
        predkosc_paletki = [0,0]

    if pilkarect.collidelistall([paletkarect]):
        predkosc[1] = -2
    #kolizje--
    
    pygame.display.flip()
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()
        #klawisze
        if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
            predkosc_paletki[0] = -4
        if event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
            predkosc_paletki[0] = 4
        if event.type == pygame.KEYUP and pygame.K_LEFT:
            predkosc_paletki[0] = 0
        if event.type == pygame.KEYUP and pygame.K_RIGHT:
            predkosc_paletki[0] = 0
        




